import React, { useState } from 'react';

const UseHook = () => {
  const useToggle = () => {
    const [value, setValue] = useState(true)
    const toggle = () => setValue(!value)
    return {
      value,
      toggle
    }
  }
  const { value, toggle } = useToggle()
  // const [value, setValue] = useState(true)
  // const toggle = () => setValue(!value)
  return (
    <div>
      {value && <div>this is div</div>}
      <button onClick={toggle}>切换</button>
    </div>
  );
};

export default UseHook;